from django.http import Http404, HttpResponse
from django.conf import settings

from Captcha import PersistentFactory


def captcha_image(request, id):
    factory = PersistentFactory(settings.CAPTCHA_PERSISTENCE)
    test = factory.get(str(id))
    if not test:
        raise Http404
    response = HttpResponse(mimetype='image/jpeg')
    test.render().save(response,'JPEG')
    return response
